package cn.com.bluemoon.daps.system.controller.api;

import cn.com.bluemoon.daps.api.sys.RemoteSystemUserService;
import cn.com.bluemoon.daps.common.annotation.FcApiFor;
import cn.com.bluemoon.daps.common.constant.ServiceNameConstants.DapsApiSystem;
import cn.com.bluemoon.daps.common.datascope.IgnorePermission;
import cn.com.bluemoon.daps.common.domain.ResultBean;
import cn.com.bluemoon.daps.system.dto.SystemUserDto;
import cn.com.bluemoon.daps.system.service.DapSystemUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author Jarod.Kong
 * @date 2020/12/21 13:59
 */
@Api(tags = {"FeignClient服务-系统用户信息"})
@RequestMapping(DapsApiSystem.API_SYS_USER)
@IgnorePermission(name = "服务注册-系统用户信息")
@RestController
@Slf4j
public class DapSysUserApi implements RemoteSystemUserService {
    @Resource(name = DapSystemUserService.DAP_SYSTEM_LOGIN_USER_SERVICE)
    private DapSystemUserService systemUserService;

    @GetMapping("/list")
    @ApiOperation(value = "获取系统用户列表")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "ok", response = ResultBean.class)})
    @IgnorePermission(name = "获取系统用户列表")
    @FcApiFor(team = {"数据资产团队", "数据工具团队"})
    public ResultBean<List<SystemUserDto>> list() {
        List<SystemUserDto> list = systemUserService.allUsers();
        return ResultBean.ok(list);
    }

    @GetMapping("/user/dba")
    @ApiOperation(value = "获取系统用户列表")
    @ApiResponses(value = {@ApiResponse(code = 200, message = "ok", response = ResultBean.class)})
    @IgnorePermission(name = "获取系统用户列表")
    @FcApiFor(team = {"数据资产团队", "数据工具团队"})
    public ResultBean<List<SystemUserDto>> userDba() {
        List<SystemUserDto> list = systemUserService.dbaUsers();
        return ResultBean.ok(list);
    }

    @Override
    public ResultBean<List<SystemUserDto>> listByAccount(List<String> accounts) {
        List<SystemUserDto> res = systemUserService.listUsersByAccount(accounts);
        return ResultBean.ok(res);
    }

}
